//
// Created by 33145 on 2023/6/1.
//

#include "io_thread_group.h"
#include "../common/rocket.h"

namespace rocket {

  IOThreadGroup::IOThreadGroup(int size) {
    _io_thread_groups.resize(size);
    for (int i = 0; i < size; i++) {
      _io_thread_groups[i] = std::make_shared<IOThread>();
    }
  }

  void IOThreadGroup::start() {
    for (const auto& IOt : _io_thread_groups) {
      IOt->start();
    }
  }

  void IOThreadGroup::join() {
    for (const auto& IOt : _io_thread_groups) {
      IOt->join();
    }
  }

  IOThread::ptr IOThreadGroup::getIOThread() {
    if (_index == (int)_io_thread_groups.size() || _index == -1)  {
      _index = 0;
    }
    return _io_thread_groups[_index++];
  }
}

